#include<iostream>

#include<string>



class Student
{
    public:
    Student()//无参构造函数：默认构造函数    在没写构造的结构体或者类里more默认会有
    {
        std::cout<<"无参构造！\n";
    }

    Student(int id,const char*name)//构造函数允许重载   
    {
        std::cout<<"有参构造!\n";
        m_id = id;
        m_name = name;
    }
    
    //拷贝构造函数
    Student(const Student &s)    //如果不用引用   会导致 无限的递归 无限的复制下去 
    {
        std::cout<<"拷贝构造函数\n";
        m_id = s.m_id;
        m_name = s.m_name;
    }
    
    //赋值运算符的重载
    void operator=(const Student &s)
    {
        std::cout<<"赋值运算符重载!\n";
        m_id = s.m_id;
        m_name = s.m_name;
    }
    


    ~Student()
    {
        std::cout<<"析构函数"<<std::endl;
    }


    void Print()
    {
        std::cout<<m_id<<" "<<m_name<<std::endl;
        
    }

    private:
        int m_id;
        std::string m_name;


};


int main()
{
    Student s1(1,"zhangsan");    // Student s; 调用的是无参构造函数，不能加括号
    Student s2;
    s2 = s1;  // 这种形式是两个都初始化完了之后，用s1的值给s2赋值
    s2.Print();
    return 0;
}





